package com.qd.common.panda.domain.entity.stroke;

import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.qd.common.panda.domain.entity.space.OrderSpaceTenantDTO;
import com.qd.common.panda.domain.entity.stroke.preferential.UserStrokeOrderPreferentialLogDTO;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 用户订单
 *
 * @author sjk
 */
@Getter
@Setter
@ToString
public class UserStrokeOrderDTO {

    /**
     * 主键
     */
    @NotBlank(message = "订单ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "订单ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String orderId;
    /**
     * 第三方订单ID
     */
    @Size(max = 64, message = "第三方订单ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String thirdPartyOrderId;
    /**
     * 开始时间
     */
    @NotNull(message = "开始时间不能为空", groups = DefaultGroup.class)
    private LocalDateTime startTime;
    /**
     * 结束时间
     */
    private LocalDateTime endTime;
    /**
     * 用户昵称
     */
    @Size(max = 200, message = "用户昵称长度不能超过{max}位", groups = DefaultGroup.class)
    private String nickName;
    /**
     * 订单金额
     */
    @NotNull(message = "订单金额不能为空", groups = DefaultGroup.class)
    private BigDecimal orderAmount;
    /**
     * 订单金额显示
     */
    private String orderAmountDisplay;
    /**
     * 实际支付金额
     */
    @NotNull(message = "实际支付金额不能为空", groups = DefaultGroup.class)
    private BigDecimal payAmount;
    /**
     * 实际支付金额显示
     */
    private String payAmountDisplay;
    /**
     * 线上支付金额
     */
    private BigDecimal onLinePayAmount;
    /**
     * 线上支付金额显示
     */
    private String onLinePayAmountDisplay;
    /**
     * 优惠金额
     */
    private BigDecimal discountAmount;
    /**
     * 优惠金额显示
     */
    private String discountAmountDisplay;
    /**
     * 服务费
     */
    private BigDecimal serviceCharge;
    /**
     * 服务费显示
     */
    private String serviceChargeDisplay;
    /**
     * 闸机编号
     */
    @Size(max = 100, message = "闸机编号长度不能超过{max}位", groups = DefaultGroup.class)
    private String machineCode;
    /**
     * 支付状态:0未支付 1支付成功 2支付失败
     */
    @NotNull(message = "支付状态不能为空", groups = DefaultGroup.class)
    private Integer payStatus;
    /**
     * 支付状态显示
     */
    private String payStatusDisplay;
    /**
     * 订单类型:0预约订单 1停车缴费订单 2超时补缴费订单
     */
    private Integer orderType;
    /**
     * 订单类型显示
     */
    private String orderTypeDisplay;
    /**
     * 行程ID
     */
    @NotBlank(message = "行程ID不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "行程ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String sid;
    /**
     * 停车场ID
     */
    @NotBlank(message = "停车场不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "停车场长度不能超过{max}位", groups = DefaultGroup.class)
    private String parkId;
    /**
     * 停车场名称
     */
    private String parkName;
    /**
     * 停车场显示
     */
    private String parkIdDisplay;
    /**
     * 车牌
     */
    @NotBlank(message = "车牌不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "车牌长度不能超过{max}位", groups = DefaultGroup.class)
    private String plateNumber;
    /**
     * 用户唯一标识
     */
    @NotBlank(message = "用户唯一标识不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "用户唯一标识长度不能超过{max}位", groups = DefaultGroup.class)
    private String userId;
    /**
     * 行程类型:0停车1充电
     */
    private Integer tripType;
    /**
     * 行程类型显示
     */
    private String tripTypeDisplay;
    /**
     * 业务ID,对应订单表中的第三方订单号
     */
    private String bid;
    /**
     * 是否ETC支付
     */
    private String etcPay;
    /**
     * 是否ETC支付显示
     */
    private String etcPayDisplay;
    /**
     * 推广码
     */
    private String promotionCode;
    /**
     * 推广码显示
     */
    private String promotionCodeDisplay;
    /**
     * 扩展字段
     */
    private String extendsFiles;
    /**
     * 充电信息
     */
    private UserStrokeOrderChargeDTO orderCharge;
    /**
     * 优惠记录
     */
    private List<UserStrokeOrderPreferentialLogDTO> orderPreferentialList;
    /**
     * 优惠记录
     */
    private ArrayNode preferentialList;
    /**
     * 加油订单
     */
    private UserStrokeOrderGasDTO orderGas;
    /**
     * 短租订单
     */
    private OrderSpaceTenantDTO spaceTenant;
    /**
     * 商城订单
     */
    private UserStrokeOrderMallDTO orderMall;
    /**
     * 退款信息
     */
    private List<UserStrokeOrderRefundDTO> refundList;

    public void freeData() {
        this.orderId = null;
        this.thirdPartyOrderId = null;
        this.startTime = null;
        this.endTime = null;
        this.nickName = null;
        this.orderAmount = null;
        this.orderAmountDisplay = null;
        this.payAmount = null;
        this.payAmountDisplay = null;
        this.onLinePayAmount = null;
        this.onLinePayAmountDisplay = null;
        this.discountAmount = null;
        this.discountAmountDisplay = null;
        this.serviceCharge = null;
        this.serviceChargeDisplay = null;
        this.machineCode = null;
        this.payStatus = null;
        this.payStatusDisplay = null;
        this.orderType = null;
        this.orderTypeDisplay = null;
        this.sid = null;
        this.parkId = null;
        this.parkName = null;
        this.parkIdDisplay = null;
        this.plateNumber = null;
        this.userId = null;
        this.tripType = null;
        this.tripTypeDisplay = null;
        this.bid = null;
        this.etcPay = null;
        this.etcPayDisplay = null;
        this.extendsFiles = null;
        this.promotionCode = null;
        this.promotionCodeDisplay = null;
        Optional.ofNullable(orderCharge).ifPresent(UserStrokeOrderChargeDTO::freeData);
        Optional.ofNullable(orderGas).ifPresent(UserStrokeOrderGasDTO::freeData);
        Optional.ofNullable(spaceTenant).ifPresent(OrderSpaceTenantDTO::freeData);
        Optional.ofNullable(orderPreferentialList).ifPresent(List::clear);
        Optional.ofNullable(orderMall).ifPresent(UserStrokeOrderMallDTO::freeData);
        this.preferentialList = null;
    }
}
